package com.wf.atm.utils;


import com.wf.atm.config.ThreadPoolConfig;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description 自定义线程池
 * @Author fqq
 * @Date 2023/9/18 14:04
 */
public class ThreadPoolUtils {
    private static ExecutorService pool;

    static {

        pool = new ThreadPoolExecutor(
                ThreadPoolConfig.CORE_POOL_SIZE,
                ThreadPoolConfig.MAX_POOL_SIZE,
                60L,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(ThreadPoolConfig.QUEUE_SIZE),
                new ThreadPoolExecutor.AbortPolicy());
    }

    //线程池中的线程 执行任务
    public static void execute(Runnable task) {
        pool.submit(task);
    }

    public static void shutDown() {
        pool.shutdown();
    }
}
